#import "ALDateElementTextField.h"
#import "SMRPopoverWindow.h"



@implementation ALDateElementTextField

@synthesize datePickerPopoverContentView;
@synthesize datePickerPopover;
@synthesize datePicker;


-(BOOL)becomeFirstResponder {
	NSRect titleRect = [self overlayRectForRect:[self visibleRect]];
	titleRect.size.width = 0;
	[[self datePickerPopover] presentPopoverFromRect:titleRect inView:self permittedArrowDirections:SMRPopoverArrowDirectionAny animated:YES];
	return [super becomeFirstResponder];
}

-(void)textDidEndEditing:(NSNotification *)aNotification {
	[[self datePickerPopover] dismissPopoverAnimated:YES];
	[super textDidEndEditing:aNotification];
}

-(void)viewDidMoveToWindow {
	if (![self datePickerPopoverContentView] || [self datePickerPopover])
		return;
	[self setDatePickerPopover:[[SMRPopoverWindow alloc] initWithContentRect:NSZeroRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES]];
	[[self datePickerPopover] setContentView:[self datePickerPopoverContentView]];
	[[self datePickerPopover] setShouldBecomeKey:NO];
}

@end
